package com.fzrskj.cloud.free.user.utils;

import com.fzrskj.cloud.free.user.bean.UserIssue;
import com.fzrskj.cloud.free.user.bean.UserIssueView;
import com.fzrskj.cloud.free.user.dao.UserIssueDao;
import ms.core.object.CObject;

import java.io.File;
import java.util.List;
import java.util.Map;

public class UserIssueUtils extends CObject{
	/**
	 * 查询工单
	 * @param cdt
	 * @param page
	 * @param pagesize
	 * @return
	 */
	public List<UserIssueView> queryIssue(Map<String, Object> cdt, int page, int pagesize){
		UserIssueDao dao= new UserIssueDao();
		List<UserIssueView> queryIssue = dao.queryIssue(cdt,page,pagesize);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return queryIssue;
	}

	/**
	 * 根据条件查询总数
	 * @param cdt
	 * @return
	 */
	public int queryIssueCount(Map<String, Object> cdt){
		UserIssueDao dao= new UserIssueDao();
		int count = dao.queryIssueCount(cdt);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return count;
	}

	/**
	 * 删除工单
	 * @param userName
	 * @param id
	 * @return
	 */
	public int delIssue(String userName,int id){
		UserIssueDao dao= new UserIssueDao();
		int ret = dao.delIssue(userName, id);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return ret;
	}

	/**
	 * 查询工单详情
	 * @param userName
	 * @param id
	 * @return
	 */
	public UserIssue queryDetails(String userName, int id){
		UserIssueDao dao= new UserIssueDao();
		UserIssue queryDetails = dao.queryDetails(userName, id);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return queryDetails;
	}

	/**
	 * 查询工单详情
	 * @param userName
	 * @param id
	 * @return
	 */
	public UserIssueView queryDetailsView(String userName,int id){
		UserIssueDao dao= new UserIssueDao();
		UserIssueView queryDetails = dao.queryDetailsView(userName, id);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return queryDetails;
	}

	/**
	 * 查询工单内容
	 * @param userName
	 * @param id
	 * @return
	 */
	public List<UserIssue> queryContent(String userName,int id,int page,int pagesize){
		UserIssueDao dao= new UserIssueDao();
		List<UserIssue> queryContent = dao.queryContent(userName, id,page,pagesize);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return queryContent;
	}

	public int queryCount(String userName,int id){
		UserIssueDao dao= new UserIssueDao();
		int count = dao.queryCount(userName,id);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return count;
	}

	/**
	 * 回复工单
	 * @param queryDetails
	 * @return
	 */
	public int replyIssue(UserIssue queryDetails){
		UserIssueDao dao= new UserIssueDao();
		int ret = dao.replyIssue(queryDetails);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return ret;
	}

	/**
	 * 修改工单
	 * @param id
	 * @return
	 */
	public int updateIssue(int id,int state){
		UserIssueDao dao= new UserIssueDao();
		int ret = dao.updateIssue(id,state);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return ret;
	}

	//删除文件
	public boolean delloadwork(String filesrc){
		boolean flag = false;
		File file = new File(filesrc);
		// 判断目录或文件是否存在
	    if (file.isFile()) {
	        file.delete();
	        flag = true;
	    }
	    return flag;
	}

	/**
	 * 查询最后回复问题
	 * @param parentIssueId
	 * @param userId
	 * @return
	 */
	public UserIssue queryLastIssue(long parentIssueId,int userId){
		UserIssueDao dao= new UserIssueDao();
		UserIssue ui = dao.queryLastIssue(parentIssueId, userId);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return ui;
	}

	/**
	 * 查询过时工单
	 * @param hour
	 * @return
	 */
	public List<UserIssue> queryObsoleteIssue(int hour){
		UserIssueDao dao= new UserIssueDao();
		List<UserIssue> queryIssue = dao.queryObsoleteIssue(hour);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return queryIssue;
	}

	/**
	 * 查询未完成工单
	 * @param issueCode
	 * @param identName
	 * @param userId
	 * @return
	 */
	public UserIssue queryNoEndUserIssue(String issueCode,String identName,int userId){
		UserIssueDao dao= new UserIssueDao();
		UserIssue ret = dao.queryNoEndUserIssue(issueCode,identName,userId);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return ret;
	}
}